package com.daipresents.gfmon.action;

import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.monitor.MonitorNotification;

import org.apache.log4j.Logger;

public class LoggingAction implements NotificationListener,  LoggingActionMBean {
    
    private Logger logger = Logger.getLogger(LoggingAction.class);
    
    public LoggingAction(){
        
    }
    
    public void handleNotification(Notification notification, Object handback) {
        
        String observedAttribute = ((MonitorNotification) notification).getObservedAttribute();
        String notificationMessage;
        if (notification.getType().equals(MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED)) {
                notificationMessage = observedAttribute + " exceeded high threshold.";
        } else {
                notificationMessage = observedAttribute + " exceeded low threshold.";
        }
        logger.debug("NOTIFICATION:" + notificationMessage);
    }
}
